package com.zzyl.controller;

import com.zzyl.annotation.HasPermission;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceListDto;
import com.zzyl.dto.addResourceDto;
import com.zzyl.entity.Resource;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @PostMapping("/list")
    @HasPermission(perms = "POST:resource:list")
    @ApiOperation("资源列表")
    public ResponseResult<List<Resource>> getResourceList(@RequestBody ResourceListDto dto) {
        List<Resource> resourceList = resourceService.getResourceList(dto);
        return ResponseResult.success(resourceList);
    }

    @PostMapping("/tree")
    @ApiOperation("资源树形")
    public ResponseResult<TreeVo> getResourceTree() {
        TreeVo treeVo = resourceService.getResourceTree();
        return ResponseResult.success(treeVo);
    }

    @PutMapping
    @ApiOperation("添加菜单")
    public ResponseResult addResource(@RequestBody addResourceDto dto) {
        resourceService.addResource(dto);
        return ResponseResult.success();
    }

}
